package com.aaa.controller.api;

import com.aaa.entity.Dept;
import com.aaa.entity.DictData;
import com.aaa.entity.DictType;
import com.aaa.service.DictTypeService;
import com.aaa.service.impl.DictTypeServiceImpl;
import com.aaa.vo.DictTypeVo;
import com.aaa.vo.Result;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/system/api/dict/type")

public class DictTypeControllerApi {
    @Autowired
    public DictTypeService dictTypeService;

    @PostMapping("searchDict/{currentPage}/{pageSize}")
    public Result<IPage<DictType>> searchDict(
            @PathVariable Integer currentPage,
            @PathVariable Integer pageSize,
            @RequestBody DictTypeVo dictTypeVo
    ){
        return dictTypeService.findByConditions(currentPage,pageSize, dictTypeVo);
    }

    //添加修改
    @PostMapping("saveAndUpdate")
    public Result saveAndUpdate(DictType dictType) {
        if (dictTypeService.saveAndUpdate(dictType)) {
            return new Result(200, "操作成功", true);
        } else {
            return new Result(500, "操作失败", false);
        }
    }

    //删除
    @DeleteMapping("delById/{id}")
    public Result delById(@PathVariable Long id){
        if (dictTypeService.delById(id)){
            return new Result(200,"修改成功",true);
        }else {
            return  new Result(500,"修改失败",false);
        }
    }
}
